package com.polytech.diploma.SQLGenerator.Oracle.Conditions;

import java.util.List;
import java.util.Map;

public class Condition implements ConditionArgument{
	protected ConditionType type;
	protected ConditionArgument leftArg;
	protected ConditionArgument rightArg;
	
	public Condition(Builder builder) 
	{
		this.type = builder.type;
		this.leftArg = builder.leftArg;
		this.rightArg = builder.rightArg;
	}
	
	public static class Builder{
		private ConditionType type;
		private ConditionArgument leftArg;
		private ConditionArgument rightArg;
		
		public Builder setType(ConditionType type) {
			this.type = type;
			return this;
		}
		public Builder setLeftArg(ConditionArgument leftArg) {
			this.leftArg = leftArg;
			return this;
		}
		public Builder setRightArg(ConditionArgument rightArg) {
			this.rightArg = rightArg;
			return this;
		}
		public Condition build()
		{
			return new Condition(this);
		}		
	}

	public ConditionType getType() {
		return type;
	}

	public ConditionArgument getLeftArg() {
		return leftArg;
	}

	public ConditionArgument getRightArg() {
		return rightArg;
	}

	@Override
	public Map<String, List<String>> getTablesWithFields(
			Map<String, List<String>> fieldMap) {
		if(leftArg != null)
			fieldMap = leftArg.getTablesWithFields(fieldMap);
		if(rightArg != null)
			fieldMap = rightArg.getTablesWithFields(fieldMap);
		return fieldMap;
	}
}
